<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="btn" uri="http://www.dsdl.com/dev/jsp/btn" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%@include file="../base/base.jspf" %>
<div class="layui-fluid">
    <div class="layui-card">
        <form class="layui-form"
              lay-filter="setmeal-setmealPage-search" id="setmeal-setmealPage-search">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">套餐名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="semName" placeholder="请输入套餐名称" autosemplete="off"
                                   class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn" type="button" lay-submit lay-filter="setmeal-setmealPage-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>

                </div>
            </div>
        </form>

        <div class="layui-card-body">
            <script type="text/html" id="toolbar-setmealListPage-setmeal">
                <div class="layui-btn-container">
                    <btn:btn btnStr="setmealAdd">
                        <button class="layui-btn" lay-event="add">新增</button>
                    </btn:btn>
                </div>
            </script>
            <table id="setmeal-setmealList-page" lay-filter="setmeal-setmealList-page"></table>
            <script type="text/html" id="table-setmealPage-btn">
                <btn:btn btnStr="setmealEdit">
                    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit"><i
                            class="layui-icon layui-icon-edit"></i>编辑</a>
                </btn:btn>
                <btn:btn btnStr="setmealDelete">
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                            class="layui-icon layui-icon-delete"></i>删除</a>
                </btn:btn>
            </script>
        </div>
    </div>
</div>



<script type="text/javascript">
    layui.config({
        base: "${ctx}/static/framework/layuiadmin/" //静态资源所在路径
    }).extend({
        index: "lib/index" //主入口模块
    }).use(["index", "table", "form"], function () {
        var table = layui.table, form = layui.form;
        table.render({
            elem: "#setmeal-setmealList-page",
            url: "${ctx}/setmeal/getSetmealList",
            method: "post",
            toolbar: "#toolbar-setmealListPage-setmeal",
            defaultToolbar: ["filter", "print","exports"],
            height: "full-125",//自己根据表格上方和下方的高度减去对应数值，保证侧边无滚动条即可
            cols: [[{
                field: "semAssociationId",
                title: "协会",
                width:200,
                templet: function (data) {
                    return xiehuiTrans(data.semAssociationId);
                }
            }, {
                field: "semName",
                title: "套餐名称",
                width: 150,
            }, {
                field: "semMoney",
                title: "费用（元）",
                width: 150,
            },{
                field: "semNum",
                title: "数量",
                width: 150,
            }, {
                field: "semUnit",
                title: "单位",
                width: 150,
                align: "center",
                templet: function (data) {
                    if(data.semUnit == 1){
                        return "月";
                    }else if(data.semUnit == 2){
                        return "季";
                    }else if(data.semUnit == 3){
                        return "年";
                    }
                }
            }, {
                field: "semCreateTime",
                title: "添加时间",
                width: 200,
                sort: true,
                templet: function (data) {
                    var dt = parseToDate(data.semCreateTime);
                    return dt.format("yyyy-MM-dd");
                }
            },{
                title: "操作",
                width: 300,
                align: "center",
                fixed: "right",
                toolbar: "#table-setmealPage-btn"
            }]],
            page: true,
            limit: 20,
            limits: [20, 50, 100],
            text: {
                none: "暂无相关数据"
            }
        });
        form.on("submit(setmeal-setmealPage-search)", function (data) {
            table.reload("setmeal-setmealList-page", {
                where: data.field,
                page: {curr: 1}
            });
        });

        //显示大图片
        showBigImage = function (e) {
            console.log(e)
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true, //点击阴影关闭
                area: [$(e).width + 'px', $(e).height + 'px'], //宽高
                content: "<img src=" + $(e).attr('src') + " />"
            });
        }

        table.on("tool(setmeal-setmealList-page)", function (obj) {
            var data = obj.data;
            if (obj.event == "del") {
                layer.confirm("您确定要删除该公司吗？", {
                    icon: 3,
                    title: "提示",
                    btn: ["确定", "取消"] //按钮
                }, function (index) {
                    tip_index = load();
                    $.ajax({
                        async: true,
                        url: "${ctx}/setmeal/setmealDelete",
                        type: "post",
                        dataType: "json",
                        data: {
                            id: data.semId
                        },
                        success: function (data1) {
                            layer.close(tip_index);
                            if (data1.result) {
                                success(data1.info);
                                table.reload("setmeal-setmealList-page");
                            } else {
                                error(data1.info);
                            }
                        }
                    });
                    layer.close(index);
                }, function (index) {
                    layer.close(index);
                });
            } else if (obj.event == "edit") {
                layer.open({
                    type: 2,
                    title: "公司编辑",
                    content: "${ctx}/setmeal/setmealSubmitPage?id="+data.semId,
                    offset: "t",
                    maxmin: true,
                    area: ["800px", "600px"],
                    btn: ["确定", "取消"],
                    yes: function (index, layero) {
                        layero.find("iframe").contents().find("#setmeal-front-submit").trigger("click");
                    }
                });
            }
        });
        table.on("toolbar(setmeal-setmealList-page)", function (obj) {
            if (obj.event == "add") {
                layer.open({
                    type: 2,
                    title: "公司添加",
                    content: "${ctx}/setmeal/setmealSubmitPage",
                    offset: "t",
                    maxmin: true,
                    area: ["800px", "600px"],
                    btn: ["确定", "取消"],
                    yes: function (index, layero) {
                        layero.find("iframe").contents().find("#setmeal-front-submit").trigger("click");
                    }
                });
            }
        });
    });
</script>